package com.zmn.oms.services.impl.conf.replay;

import com.zmn.common.dto.StatusDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.oms.model.entity.conf.reply.ReplyQuestion;
import com.zmn.oms.model.entity.conf.reply.ReplyQuestionQuery;
import com.zmn.oms.persistence.interfaces.conf.reply.ReplyQuestionDao;
import com.zmn.oms.services.interfaces.conf.reply.ReplyQuestionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 描述: 回访内容表基础接口实现类
 *
 * @author tanghongjun
 * @since 2020-04-14 11:27:25
 **/
@Slf4j
@Service
public class ReplyQuestionServiceImpl implements ReplyQuestionService {

    private static final String TAG = "回访内容表基础服务接口";

    @Resource
    private ReplyQuestionDao replyQuestionDao;

    /**
     * 描述: 根据id查询数据
     *
     * @param questionId
     *            id
     * @author tanghongjun
     * @since 2020-04-14 11:27:25
     **/
    @Override
    public ReplyQuestion findById(Integer questionId) {

        if (Objects.isNull(questionId)) {
            log.error("[{}],根据id查询数据questionId为null", TAG);
            return null;
        }
        return replyQuestionDao.findById(questionId);
    }

    @Override
    public Integer findMaxSort() {
        return replyQuestionDao.findMaxSort();
    }

    /**
     * 描述: 按条件查询数据 支持分页
     *
     * @param query
     *            查询对象
     * @author tanghongjun
     * @since 2020-04-14 11:27:25
     **/
    @Override
    public List<ReplyQuestion> listPageByQuery(ReplyQuestionQuery query) {

        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        int count = replyQuestionDao.countByQuery(query);
        query.setTotalCount(count);
        return replyQuestionDao.listPageByQuery(query);
    }

    /**
     * 描述: 按条件查询数据 不支持分页
     *
     * @param query
     *            查询对象
     * @author tanghongjun
     * @since 2020-04-14 11:27:25
     **/
    @Override
    public List<ReplyQuestion> listByQuery(ReplyQuestionQuery query) {
        return replyQuestionDao.listByQuery(query);
    }

    /**
     * 描述: 根据id修改数据 id为必传
     *
     * @param replyQuestion
     *            待修改数据
     * @return java.lang.Integer
     * @author tanghongjun
     * @since 2019/11/12
     **/
    @Override
    public Integer updateReturnVisitQuestionByKey(ReplyQuestion replyQuestion) {
        return replyQuestionDao.updateReturnVisitQuestionByKey(replyQuestion);
    }

    @Override
    public int updateStatusBatch(List<Integer> arrayIds, int status, String updater) {
        StatusDTO dto = new StatusDTO();
        dto.setIds(arrayIds);
        dto.setStatus(status);
        dto.setUpdater(updater);
        dto.setUpdateTime(DateUtil.getNow());
        return replyQuestionDao.updateStatusBatch(dto);
    }

    @Override
    public Integer updateSortKey(int id, int sort, String updater) {
        ReplyQuestion replyQuestion = new ReplyQuestion();
        replyQuestion.setQuestionId(id);
        replyQuestion.setSort(sort);
        replyQuestion.setUpdater(updater);
        replyQuestion.setUpdateTime(DateUtil.getNow());
        return replyQuestionDao.updateSortKey(replyQuestion);
    }

    @Override
    public Integer updateFirstLetterByKey(int id, String firstLetter, String updater) {
        ReplyQuestion replyQuestion = new ReplyQuestion();
        replyQuestion.setQuestionId(id);
        replyQuestion.setFirstLetter(firstLetter);
        replyQuestion.setUpdater(updater);
        replyQuestion.setUpdateTime(DateUtil.getNow());
        return replyQuestionDao.updateFirstLetterByKey(replyQuestion);
    }

    /**
     * 描述: 新增数据
     *
     * @param replyQuestion
     *            待新增数据
     * @return java.lang.Integer 主键key
     * @author tanghongjun
     * @since 2019/11/12
     **/
    @Override
    public Integer insert(ReplyQuestion replyQuestion) {
        return replyQuestionDao.insert(replyQuestion);
    }

}